package eecs285.proj4.gui;

//Class: EECS 285
//Project: 
//Due Date: Monday December 6th, 2010

//NOTES: 

import java.awt.*;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;


import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.*;

//import sun.reflect.Reflection;

import static eecs.util.Utility.*;

//@XmlRootElement(name = "MAction")
//@XmlAccessorType(XmlAccessType.FIELD)
/**
 * The base class for actions performed on a Markerboard. All actions inherit
 * from this class.
 * 
 * @author Easton Thomas
 * @author Hans Marquard
 */
@SuppressWarnings("serial")
public class MAction implements Serializable
{
  public enum TYPE
  {
    TEXT, LINE, CIRCLE, RECTANGLE, ERASE, FREEDRAW
  };

  // ---------------------------------------------------------------------------

  private static boolean DEBUG_MODE = Markerboard.DEBUG_MODE;
  private static int DEFAULT_STROKE_WIDTH = 20;

  // Is Mine?
  protected Boolean mine; // What does this do?

  // FreeDraw/Erase Array points of mouse movement.
  // NOTE: ArrayList (like Vector) allows constant-time insertion at the ends,
  // but unlike Vector, there is no overhead for synchronization. Also, Vector
  // increases its capacity by doubling. ArrayList increases capacity more
  // gradually, +50% at a time.
  protected ArrayList<Point> points;
  // Color
  protected Color color;
  // BrushWidth
  protected int stroke;
  // Start
  protected Point start_pt;
  // End
  protected Point end_pt;
  // Type
  protected TYPE type;
  
  private Long ID_unique = (Double.doubleToLongBits(Math.random()));
  
  

  // ---------------------------------------------------------------------------

  @Override
  public boolean equals(Object obj)
  {
    if( this == obj )
    {
      return true;
    }
    if( obj == null )
    {
      return false;
    }
    if( !(obj instanceof MAction) )
    {
      return false;
    }
    MAction other = (MAction) obj;
    if( ID_unique == null )
    {
      if( other.ID_unique != null )
      {
        return false;
      }
    }
    else if( !ID_unique.equals(other.ID_unique) )
    {
      return false;
    }
    return true;
  }

  /**
   * Base constructor.
   * 
   * @param type_
   *          The actual derived type of action.
   * @author Easton Thomas
   * @author Hans Marquard
   */
  public MAction(TYPE type_)
  {
    // initialize here
    color = Color.BLACK;
    stroke = DEFAULT_STROKE_WIDTH;
    start_pt = new Point(0, 0);
    end_pt = new Point(0, 0);

    type = type_;
  }

  // ---------------------------------------------------------------------------

  public void draw(Graphics2D g2)
  {
    assert "Not supported here in base class." == null;
    // the draw function in the graphics instance g
  }

  // ---------------------------------------------------------------------------

  /**
   * Gets the MAction.TYPE of this action.
   * 
   * @return MAction.TYPE of this action.
   * @author Hans Marquard
   */
  public TYPE getType()
  {
    return type;
  }

  // ---------------------------------------------------------------------------

  /**
   * Sets the color for this action.
   * 
   * @param color_
   *          The color to be used.

   * @author Hans Marquard
   */
  public void setColor(Color color_)
  {
    color = color_;
  }

  // ---------------------------------------------------------------------------

  /**
   * Sets the actual stroke to use when drawing.
   * 
   * @param stroke_
   *          A Stroke object.
   * @author Easton Thomas
   */
  public void setStroke(int stroke_)
  {
    stroke = stroke_;
  }

  // ---------------------------------------------------------------------------

  /**
   * Gets the current stroke used when drawing.
   * 
   * @return The current stroke value.
   * @author Easton Thomas
   */
  public int getStroke()
  {
    return stroke;
  }

  // ---------------------------------------------------------------------------

  /**
   * Sets the start point of this action.
   * 
   * @param point_
   *          The start point. For circles, this is the center. For rectangles,
   *          the upper left corner.
   * @author Hans Marquard
   */
  public void setStart(Point point_)
  {
    start_pt = point_;
  }

  // ---------------------------------------------------------------------------

  /**
   * Sets the end point for this action. Note: not all actions have an end
   * point.
   * 
   * @param point_
   *          The end point.
   * @author Hans Marquard
   */
  public void setEnd(Point point_)
  {
    end_pt = point_;
  }
  // ---------------------------------------------------------------------------

  
  // ---------------------------------------------------------------------------

  /**
   * Sets the text.
   * 
   * @param text_
   *          The text to display.
   * @author Hans Marquard
   */
  public void setText(String text_)
  {}
  
  // ---------------------------------------------------------------------------

  /**
   * Gets the text.
   * 
   * @return The text used when drawing.
   * @author Vidal Borromeo
   */
  public String getText()
  {return "";}
  
  // ---------------------------------------------------------------------------

  /**
   * Sets the font size.
   * 
   * @param size_ The size.
   * @author Hans Marquard
   */
  public void setFontSize(int size_)
  {  }

  // ---------------------------------------------------------------------------

  /**
   * Sets the font directly.
   * 
   * @param font_ The font.
   * @author Han Solo
   */
  public void setFont(Font font_)
  {}
  
  // ---------------------------------------------------------------------------

  /**
   * Sets the font by its common name.
   * 
   * @param font_name The font name.
   * @author Han Solo
   */
  public void setFontByName(String font_name)
  { }
  
  // ---------------------------------------------------------------------------

  /**
   * Include an additional Point in the mouse movement.
   * 
   * @author Hans Marquard
   */
  public void add_point(Point new_point)
  { }
  
  // ---------------------------------------------------------------------------

  /**
   * Gets the circle radius.
   * 
   * @return The radius of the circle.
   * @author Hans Marquard
   */
  int get_radius()
  {return 0; }

}// MAction
